package org.hxyjs.controller;

import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.hxyjs.dto.DTO;
import org.hxyjs.entity.Admin;
import org.hxyjs.page.PageInfo;
import org.hxyjs.service.AdminService;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

@CrossOrigin
@Controller
@RequestMapping("/adminController")
public class AdminController {
	@Resource
	AdminService adminService;
	@RequiresPermissions("admin:getAll")
	@RequestMapping("/getAllAdmin")
	@ResponseBody //把方法的返回值按json转换之后 输出到浏览器
    public DTO<Admin> getAllAdmin() throws Exception {
    	System.out.println("查询全部管理员");
		return adminService.getAllAdmins();
    }

	@RequestMapping("/deleteAdminByAno/{ano}")
	@ResponseBody
    public DTO<Admin> deleteAdminByAno(@PathVariable("ano") String ano) throws Exception {//如何从页面传入参数到方法 用这个注解绑定变量@PathVariable
    	System.out.println(ano+"删除管理员");
    	return adminService.deleteAdminByAno(ano);
    }

	@RequestMapping("/updateAdminByAno")
	@ResponseBody
	public DTO<Admin> updateAdminByAno(@RequestBody Admin admin) throws Exception {//如何从页面传入参数到方法 用这个注解绑定变量@PathVariable
		System.out.println("修改管理员");
		return adminService.updateAdminByAno(admin);
	}


	@RequestMapping("/addAdmin")
	@ResponseBody
	public DTO<Admin> addAdmin(@RequestBody Admin admin) throws Exception {//如何从页面传入参数到方法 用这个注解绑定变量@PathVariable
		System.out.println("增加管理员");
		System.out.println(admin);
 		return adminService.addAdmin(admin);
	}

	@RequestMapping("/getAdminByPage")
	@ResponseBody
	public DTO<Admin> getAdminByPage(PageInfo pageInfo) throws Exception{//如何从页面传入参数到方法 用这个注解绑定变量@PathVariable
		System.out.println("分页管理员");
		return adminService.getAdminByPage(pageInfo);
	}

}